package com.yzkj.framework.beans.result;

import lombok.Data;

/**
 * 统一的api返回对象
 */
@Data
public class ApiResponse<T> {

    private Integer code;

    private String msg;

    private T data;

    public static <T> ApiResponse<T> success() {
        return new ApiResponse<>(ApiStatus.SUCCESS.getCode(), ApiStatus.SUCCESS.getMessage(), null);
    }

    public static <T> ApiResponse<T> success(T data) {
        return new ApiResponse<>(ApiStatus.SUCCESS.getCode(), ApiStatus.SUCCESS.getMessage(), data);
    }

    public static <T> ApiResponse<T> fail() {
        return new ApiResponse<>(ApiStatus.INTERNAL_SERVER_ERROR.getCode(), ApiStatus.INTERNAL_SERVER_ERROR.getMessage(), null);
    }

    public static <T> ApiResponse<T> fail(ApiStatus apiStatus) {
        return new ApiResponse<>(apiStatus.getCode(), apiStatus.getMessage(), null);
    }

    public static <T> ApiResponse<T> fail(ApiStatus apiStatus, T data) {
        return new ApiResponse<>(apiStatus.getCode(), apiStatus.getMessage(), data);
    }

    public static <T> ApiResponse<T> fail(Integer code, String message) {
        return new ApiResponse<>(code, message, null);
    }

    public static <T> ApiResponse<T> fail(Integer code, String message, T data) {
        return new ApiResponse<>(code, message, data);
    }

    private ApiResponse() {

    }

    private ApiResponse(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private ApiResponse(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
}
